package adb.group.entity;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class AddDrug
 */
public class AddDrug extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddDrug() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String drugId=request.getParameter("drugID");
		String drugName=request.getParameter("drugName");
		int quantity=Integer.parseInt(request.getParameter("drugQuantity"));
		float price=Float.parseFloat(request.getParameter("price"));
		
		try {
			Class.forName("oracle.jdbc.driver.OracleDriver");
			Connection connection = (Connection) DriverManager.getConnection(
					"jdbc:oracle:thin:@localhost:1521:ORCL", "dbfp_dba",
					"dbfpdba");
			Statement statement = (Statement) connection.createStatement();
			statement.executeQuery("insert into drug_t values('"
							+ drugId + "',"+price+",'"+drugName+"',"+quantity+")");
			
		      response.sendRedirect("/project/resources/common/workunit.jsp");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request,response);
	}

}
